/**
 * 详情对话框
 */
var StorageOutDetailedInfoDlg = {
    data: {
        storageOutNumber: "",
        trayNumber: "",
        storagePostionName: "",
        storagePostionNumber: "",
        storageGoodscode: "",
        storageGoodsId: "",
        storageGoodsname: "",
        storagePutbalenum: "",
        storageNumber: "",
        storageWeight: "",
        storageVolume: "",
        storagePrice: "",
        storageMoney: "",
        storageBatchnumber: "",
        storageDate: "",
        storageRebubbles: "",
        storagePacking: "",
        storageLargeclass: "",
        storageGoodstype: "",
        storagePutcondition: "",
        storageOutStatus: "",
        notes: "",
        version: "",
        createTime: "",
        updateTime: "",
        createUser: "",
        updateUser: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/storageOutDetailed/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('storageOutDetailedForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/storageOutDetailed/editItem", function (data) {
            Feng.success("更新成功！");
            var Index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(Index);
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //除以的精确结果
    function accDiv(arg1,arg2){
        var t1=0,t2=0,r1,r2;
        try{
            t1=arg1.toString().split(".")[1].length;
        }catch(e){}

        try{
            t2=arg2.toString().split(".")[1].length;
        }catch(e){}

        with(Math){
            r1=Number(arg1.toString().replace(".",""));
            r2=Number(arg2.toString().replace(".",""));
            return (r1/r2)*pow(10,t2-t1);
        }
    }

    //乘以的精确结果
    function accMul(arg1,arg2){
        var m=0,s1=arg1.toString(),
            s2=arg2.toString();
        try{
            m+=s1.split(".")[1].length}catch(e){}
        try{
            m+=s2.split(".")[1].length}catch(e){}
        return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m
        )}

    //点击库位编号
    $("#storagePostionNumber").click(function(){
        layer.open({
            type: 2,
            title: '选择库位',
            area: ['700px', '400px'],
            content: Feng.ctxPath + '/storageOutDetailed/toChosePosition?storageOutNumber='+$("#storageOutNumber").val(),
            end: function () {
                $("#storagePostionNumber").val(StorageOutDetailedInfoDlg.data.storagePostionNumber);//库位编号
            }
        });
    });

    //输入大包数量
    $("#storagePutbalenum").keyup(function(){
        var storagePutNum = $("#storagePutbalenum").val();//大包数量
        var goodsVolume = $("#goodsVolume").val();//体积
        var goodsWeight = $("#goodsWeight").val();//重量
        var storagePrice = $("#storagePrice").val();//单价
        $("#storageNumber").val(storagePutNum);//改变应出数量
        $("#storageVolume").val(accMul(storagePutNum,goodsVolume));//改变应出体积
        $("#putWeight").val(accMul(storagePutNum,goodsWeight));//改变应出重量
        $("#singleMoney").val(accMul(storagePutNum,storagePrice));//改变金额
    });

    //输入应入数量
    $("#storageNumber").keyup(function(){
        var storageNumber = $("#storageNumber").val();//应出数量
        var goodsVolume = $("#goodsVolume").val();//体积
        var goodsWeight = $("#goodsWeight").val();//重量
        var storagePrice = $("#storagePrice").val();//单价
        $("#storagePutbalenum").val(storageNumber);//改变应出大包数量
        $("#storageVolume").val(accMul(storageNumber,goodsVolume));//改变应出体积
        $("#putWeight").val(accMul(storageNumber,goodsWeight));//改变应出重量
        $("#singleMoney").val(accMul(storageNumber,storagePrice));//改变金额
    });

    //输入单价
    $("#storagePrice").keyup(function(){
        var storageNumber = $("#storageNumber").val();//应出数量
        var storagePrice = $("#storagePrice").val();//单价
        $("#singleMoney").val(accMul(storageNumber,storagePrice));//改变金额
    });

    //输入金额
    $("#storageMoney").keyup(function(){
        var storageNumber = $("#storageNumber").val();//应出数量
        var storageMoney = $("#storageMoney").val();//金额
        $("#storagePrice").val(accDiv(storageMoney,storageNumber));//改变单价
    });

    //返回按钮
    $("#backupPage").click(function () {
        var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    });

});